package org.infodavid.common.model.impl;

import org.infodavid.common.model.components.IPhone;
import org.infodavid.common.model.impl.AbstractBasicDataObjectImpl;

/**
 * The Class PhoneImpl.
 */
public class PhoneImpl extends AbstractBasicDataObjectImpl implements IPhone {

	/** serialVersionUID. */
	private static final long serialVersionUID = 5188733198966203778L;

	/** The type. */
	private IPhone.EPhoneType type;

	/** The value. */
	private String value;

	/**
	 * The Constructor.
	 * @throws Exception the exception
	 */
	protected PhoneImpl() throws Exception {
		super();
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.IPhone#getValue()
	 */
	public String getValue() {
		return value;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.IPhone#setValue(java.lang.String)
	 */
	public void setValue(final String arg0) {
		if (!equals(value, arg0)) {
			value = arg0;
			markModified(VALUE);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.IPhone#getType()
	 */
	public EPhoneType getType() {
		return type;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.IPhone#setType(org.infodavid.common.model
	 * .entities.IPhone.EPhoneType)
	 */
	public void setType(final EPhoneType arg0) {
		if (!equals(type, arg0)) {
			type = arg0;
			markModified(TYPE);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.IBasicDataObject#init()
	 */
	@Override
	public void init() throws Exception {
		super.init();

		type = null;
		value = null;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		final int result = 1;

		return prime * result + (getValue() == null ? 0 : getValue().hashCode());
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}

		if (obj == null) {
			return false;
		}

		if (!(obj instanceof IPhone)) {
			return false;
		}

		final IPhone other = (IPhone)obj;

		if (getValue() == null) {
			if (other.getValue() != null) {
				return false;
			}
		}
		else if (!getValue().equals(other.getValue())) {
			return false;
		}

		return true;
	}

	/*
	 * See super class or interface. (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		final StringBuilder builder = new StringBuilder();

		builder.append(super.toString());
		builder.append(" [type=");
		builder.append(type);
		builder.append(", value=");
		builder.append(value);
		builder.append("]");

		return builder.toString();
	}
}
